<style>
    .layui-table-cell .layui-table-sort {
        display: none;
    }

    .layui-table-view .layui-table-tool-self {
        display: flex;
        justify-content: flex-end;
        position: initial;
        margin-top: 12px;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label">处置部门：</label>
                                    <div class="layui-input-inline">
                                        <input id="departmentSearchClaimId" name="departmentSearchClaimId"
                                               type="hidden"/>
                                        <div id="departmentSearchClaim"></div>
                                    </div>
                                </div>
                                <!-- 责任岗位 -->
                                <div class="layui-inline">
                                    <label class="layui-form-label">责任岗位：</label>
                                    <div class="layui-input-inline">
                                        <select id='postIdSearchClaim' name="postIdSearchClaim"
                                                lay-filter="postIdSearchClaim"
                                                class="common-select-search">
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">状态：</label>
                                    <div class="layui-input-inline">
                                        <select name="statusSearch_claim" lay-filter="statusSearch_claim"
                                                class="common-select-search">
                                            <option value="">请选择状态</option>
                                            <option value="1">待认领</option>
                                            <option value="2">已认领</option>
                                            <option value="3">完成</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">任务编码：</label>
                                    <div class="layui-input-inline">
                                        <input name="taskNo" id="taskNo" class="layui-input" type="text"
                                               placeholder="请输入任务编码" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">录入人：</label>
                                    <div class="layui-input-inline">
                                        <input name="createName" id="createName" class="layui-input" type="text"
                                               placeholder="请输入录入人" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">认领人：</label>
                                    <div class="layui-input-inline">
                                        <input name="claimName" id="claimName" class="layui-input" type="text"
                                               placeholder="请输入认领人" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">设备清单编号：</label>
                                    <div class="layui-input-inline">
                                        <input name="deviceNo" id="deviceNo" class="layui-input" type="text"
                                               placeholder="请输入设备清单编号" autocomplete="off"/>
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                            lay-submit layui-form-keyDownSearch="true">查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>
                                        重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="maintenanceTableInfo" lay-filter="maintenanceTableInfo"></table>
        </div>
    </div>
</div>

<script type="text/html" id="viewAttachmentHtml">
    <div id="example1" style="height: 100%;"></div>
</script>

<!-- 表格操作列 -->
<script type="text/html" id="maintenanceTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    {{# if(d.status !='4') {  }}
    <a class="layui-btn layui-btn-xs" lay-event="addExecute">添加执行记录</a>
    {{# } }}
</script>

<script type="text/html" id="maintenanceExecuteForm">
    <form lay-filter="maintenanceExecuteForm" class="layui-form open-form">
        <div class="open-model">
            <div class="open-auto">
                <input name="id" type="hidden"/>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">任务类型：</label>
                        <input id="taskType" type="hidden" value="1"/>
                        <div class="layui-input-block">
                            <div style="padding-top: 9px;">
                                <span style="color: red">认领任务</span>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">设备清单：</label>
                        <div class="layui-input-block">
                            <select disabled lay-search="" id="deviceNoShowEdit" name="deviceNo" lay-filter="deviceNo"
                                    class="common-select-search">
                                <option value="">请选择设备清单号</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">设备类型：</label>
                        <div class="layui-input-block">
                            <input id="deviceLX" type="text" class="layui-input" disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">设备分类：</label>
                        <div class="layui-input-block">
                            <input id="deviceFL" type="text" class="layui-input" disabled/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">所属产线：</label>
                        <div class="layui-input-block">
                            <input id="deviceCX" name="deviceCX" type="text" class="layui-input" disabled/>
                        </div>
                    </div>

                    <div class="layui-col-md3">
                        <label class="layui-form-label">任务性质：</label>
                        <div class="layui-input-block">
                            <select id="toolDeviceType" name="taskNature" disabled lay-filter="taskNature"
                                    class="common-select-search"></select>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">维保类型：</label>
                        <div class="layui-input-block">
                            <select id="maintenanceType" name="maintenanceType" disabled lay-filter="maintenanceType"
                                    class="common-select-search">
                            </select>
                        </div>
                    </div>

                    <div class="layui-col-md3">
                        <label class="layui-form-label">设备点位：</label>
                        <div class="layui-input-block">
                            <input id="deviceLocation" name="deviceLocation" disabled type="text"
                                   class="layui-input" required autocomplete="off"/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">实施前图片：</label>
                        <div class="layui-input-block">
                            <div id="ProPic_path" class="companyFormPhotos"></div>
                            <div id="ProPicBtn" class="layui-btn" style="float: left;">
                                <i class="layui-icon">&#xe681;</i>上传实施前图片
                            </div>
                            <input name="preImg" type="hidden" class="layui-input" lay-verify="" id="preImg"/>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">实施后图片：</label>
                        <div class="layui-input-block">
                            <div id="PostPic_path" class="companyFormPhotos"></div>
                            <div id="PostPicBtn" class="layui-btn" style="float: left;">
                                <i class="layui-icon">&#xe681;</i>上传实施后图片
                            </div>
                            <input name="postImg" type="hidden" class="layui-input" lay-verify="" id="postImg"/>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">实际用时：</label>
                        <div class="layui-input-block">
                            <input id="userTime" name="userTime" placeholder="请输入实际用时" type="text"
                                   class="layui-input" lay-verify="required" required autocomplete="off"/>
                        </div>
                    </div>

                    <div class="layui-col-md3">
                        <label class="layui-form-label">停机时间：</label>
                        <div class="layui-input-block">
                            <input type="text" id="stopTime" class="layui-input" name="stopTime"
                                   placeholder="请选择停机时间">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">任务备注：</label>
                        <div class="layui-input-block">
                        <textarea name="taskRemark" placeholder="请输入任务备注" class="layui-textarea"
                                  autocomplete="off"/>
                        </div>
                    </div>

                    <!--        <div class="layui-form-item">-->
                    <!--            <label class="layui-form-label">所属成本中心:</label>-->
                    <!--            <div class="layui-input-block">-->
                    <!--                <select lay-search="" id="costCenterEdit" name="deviceNo" lay-filter="costCenter"-->
                    <!--                        class="common-select-search">-->
                    <!--                    <option value="">请选择所属成本中心</option>-->
                    <!--                </select>-->
                    <!--            </div>-->
                    <!--        </div>-->
                    <div class="layui-col-md6">
                        <label class="layui-form-label">故障现象：</label>
                        <div class="layui-input-block">
                        <textarea name="faultDescription" placeholder="请输入故障现象描述" class="layui-textarea"
                                  autocomplete="off"/>
                        </div>
                    </div>
                </div>


                <div class="layui-form-item layui-row">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">排除方法：</label>
                        <div class="layui-input-block">
                        <textarea name="repairDescription" placeholder="请输入故障排除方法" class="layui-textarea"
                                  autocomplete="off"/>
                        </div>
                    </div>

                    <div class="layui-col-md6">
                        <label class="layui-form-label">遗留问题：</label>
                        <div class="layui-input-block">
                        <textarea name="remainingProblems" placeholder="请输入遗留问" class="layui-textarea"
                                  autocomplete="off"/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">故障原因：</label>
                        <div class="layui-input-block">
                        <textarea name="faultReason" placeholder="请输入故障原因" class="layui-textarea"
                                  autocomplete="off"/>
                        </div>
                    </div>

                    <div class="layui-col-md3">
                        <label class="layui-form-label" style="width: 98px">用料总金额：</label>
                        <div class="layui-input-block" style="width: 74%;margin-left: 128px;">
                            <input id="materialAmount" style="color: red" name="materialAmount" placeholder="用料总金额"
                                   type="text"
                                   class="layui-input" lay-verify="required" required autocomplete="off"/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">用料明细：</label>
                        <div class="layui-input-block">
                            <table class="layui-table" name="maintenanExecuteDetailVos" id="maintenanExecuteDetailVos"
                                   lay-filter="maintenanExecuteDetailVos"></table>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">执行人：</label>
                        <div class="layui-input-block">
                            <input id="creatorName" name="creatorName" type="text"
                                   class="layui-input" disabled required autocomplete="off"/>
                        </div>
                    </div>
                    <div class="layui-col-md5">
                        <label class="layui-form-label">任务名称：</label>
                        <div class="layui-input-block">
                            <div style="padding-top: 9px;">
                                <span style="color: red" id="sbqdbh">设备清单编号</span>
                                <span style="color: red" id="dwh">-点位号</span>
                                <span style="color: red" id="sbmc">-设备名称</span>
                                <span style="color: red" id="rwlx">-维保认领任务</span>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">结束备注：</label>
                        <div class="layui-input-block">
                            <input id="endRemark" placeholder="请输入结束备注" name="endRemark" type="text"
                                   class="layui-input" required autocomplete="off"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item text-right">
                <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
                <button class="layui-btn" lay-filter="maintenanceTypeFormSubmit" lay-submit>保存</button>
            </div>
        </div>
    </form>
</script>

<!-- 详情 -->
<script type="text/html" id="maintenanceDetailForm">
    <form lay-filter="maintenanceDetailForm" class="layui-form open-form">
        <div class="open-model">
            <div class="open-auto">
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md4">
                        <label class="layui-form-label">任务编号：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" style="color: red" id="taskNoDetail" disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">任务名称：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" style="color: red" id="taskNameDetail" disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">任务类型：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" style="color: red" id="taskTypeNameDetail" value="1"/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md4">
                        <label class="layui-form-label" style="width: 84px;">设备清单号：</label>
                        <div class="layui-input-block" style="width: 77%;
    margin-left: 114px">
                            <input class="layui-input" id="deviceNoDetail" disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">设备类型：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="deviceLXDetail" disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">设备分类：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="deviceFLDetail" disabled/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md4">
                        <label class="layui-form-label">所属产线：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="deviceCXDetail" disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">任务性质：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="taskNatureDetail" disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">维保类型：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="maintenanceTypeDetail" disabled/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md4">
                        <label class="layui-form-label">维保点位：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="deviceLocationDetail" disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">处置部门：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="departmentIdDetail" disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">责任岗位：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="postIdDetail" disabled/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md4">
                        <label class="layui-form-label" style="width: 84px">实施前图片：</label>
                        <div class="layui-input-block">
                            <div id="proImage" class="companyFormPhotos">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label" style="width: 84px">实施后图片：</label>
                        <div class="layui-input-block">
                            <div id="postImage" class="companyFormPhotos">
                            </div>
                        </div>

                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label" style="width: 98px">用料总金额：</label>
                        <div class="layui-input-block" style="width: 74%;margin-left: 128px;">
                            <input class="layui-input" style="color: red" id="totalMoney" disabled/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">用料明细：</label>
                        <div class="layui-input-block">
                            <table class="layui-table" id="maintenanceExecuteDetailInfo"
                                   lay-filter="maintenanceExecuteDetailInfo"></table>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">任务备注：</label>
                        <div class="layui-input-block">
                <textarea id='taskRemarkDetail' name="taskRemarkDetail"
                          class="layui-textarea" autocomplete="off"
                          disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">完成备注：</label>
                        <div class="layui-input-block">
                <textarea id='endRemarkDetail' name="endRemarkDetail"
                          class="layui-textarea" autocomplete="off"
                          disabled/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md4">
                        <label class="layui-form-label">提交人：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="createNameDetail" disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">提交时间：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="createTimeDetail" disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">审核结果：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="examineTypeNameDetail" disabled/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md4">
                        <label class="layui-form-label">审核时间：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="examineTimeDetail" disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label" style="width: 98px">认领记录编号：</label>
                        <div class="layui-input-block" style="width: 74%;
    margin-left: 128px;">
                            <input class="layui-input" style="color: red" id="claimNoDetail" disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">认领时间：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="claimTimeDetail" disabled/>
                        </div>
                    </div>
                </div>
                <!--        <div class="layui-form-item">-->
                <!--            <label class="layui-form-label">处置结果：</label>-->
                <!--            <div class="layui-input-block">-->
                <!--                <input class="layui-input" id="executeStatusNameDetail" disabled/>-->
                <!--            </div>-->
                <!--        </div>-->
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md4">
                        <label class="layui-form-label" style="width: 98px">处置记录编号：</label>
                        <div class="layui-input-block" style="width: 74%;margin-left: 128px;">
                            <input class="layui-input" id="executeNoDetail" disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">处置人：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="executeNameDetail" disabled/>
                        </div>
                    </div>
                    <div class="layui-col-md4">
                        <label class="layui-form-label">处置时间：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" id="executeTimeDetail" disabled/>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-row">
                    <div class="layui-col-md4">
                        <label class="layui-form-label">状态：</label>
                        <div class="layui-input-block">
                            <input class="layui-input" style="color: red" id="statusDetail" disabled/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item text-right">
                <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">关闭</button>
            </div>
        </div>
    </form>
</script>

<!-- SKU物料列表 -->
<script type="text/html" id="erpInventoryListEdit">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline mr0">
                            <input id="erpInventoryListEdit-code" class="layui-input search-input" type="text"
                                   placeholder="输入物料编号"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline mr0">
                            <input id="erpInventoryListEdit-name" class="layui-input search-input" type="text"
                                   placeholder="输入物料名称"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline mr0">
                            <select id="erpInventoryListEdit-way">
                                <option value="">请选择计价方式</option>
                                <option value="0">按件</option>
                                <option value="1">按重量</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input id="addSelfCollectedGoodsProductCategoryId"
                                   name="addSelfCollectedGoodsProductCategoryId" type="hidden" lay-verify="required">
                            <div class="layui-input-inline mr0" id="selectProductType"></div>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="erpInventoryListEdit-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索
                        </button>
                        <button id="erpInventoryListEdit-btn-choose" class="layui-btn layui-btn-normal">确认选择
                        </button>
                    </div>
                </div>
            </div>
            <table class="layui-table" id="erpInventoryListEdit-table" lay-filter="erpInventoryListEdit-table"></table>
        </div>
    </div>
</script>

<script>
    layui.use(['layer', 'admin', 'form', 'table', 'admin', 'config', 'upload', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var laydate = layui.laydate;
        var upload = layui.upload;

        //部门列表
        admin.initDataSelectTree(true, 'user/admin/role/getTreeData', null, 'departmentSearchClaim', null, "部门", "departmentSearchClaimId", function (data) {
            // 获取部门ID
            let departmentId = data.change[0].value;
            //赋值部门id
            $('#departmentId').val(data.change[0].value);
            $('#postIdDown').empty();
            //部门下的岗位列表
            admin.initDataSelect("user/admin/role/getPostData", {roleId: departmentId}, "postIdSearchClaim", null, "岗位", null, null);
        });
        //渲染下拉
        form.render('select');

        // 渲染表格
        var insTb = table.render({
            elem: '#maintenanceTableInfo',
            url: config.base + 'enterprise/device/admin/maintenanceClaim/list',
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号', fixed: 'left'}
                , {align: 'center', field: 'taskNo', sort: true, title: '任务编号', fixed: 'left', width: '14%'}
                , {
                    align: 'center',
                    field: 'maintenanceTypeName',
                    sort: true,
                    title: '维保类型',
                    fixed: 'left',
                }
                , {align: 'center', field: 'taskNatureName', sort: true, title: '任务性质'}
                , {align: 'center', field: 'deviceNo', sort: true, title: '设备清单编码'}
                , {align: 'center', field: 'departmentName', sort: true, title: '处置部门'}
                , {align: 'center', field: 'postName', sort: true, title: '处置岗位'}
                , {align: 'center', field: 'taskTypeName', sort: true, title: '任务类型'}
                , {align: 'center', field: 'statusName', sort: true, title: '状态', width: '4%'}
                , {align: 'center', field: 'creatorName', sort: true, title: '录入人'}
                , {align: 'center', field: 'createTime', sort: true, title: '录入时间'}
                , {align: 'center', field: 'claimName', sort: true, title: '认领人'}
                , {align: 'center', field: 'claimTime', sort: true, title: '认领时间'}
                , {align: 'center', field: 'taskRemark', sort: true, title: '描述', width: '8%'}
                , {align: 'center', toolbar: '#maintenanceTableBar', title: '操作', width: '180', fixed: 'right'}
            ]],
            done: function (res, curr, count) {
                //移除按钮
                var menuButton = config.getMenuButton(location.hash);
                if (menuButton.indexOf("搜索") == -1) {
                    $('.layui-form.toolbar').remove();
                }
                if (menuButton.indexOf("修改") == -1) {
                    $("[lay-event='edit']").remove();
                }
                if (menuButton.indexOf("删除") == -1) {
                    $("[lay-event='del']").remove();
                }
            }
        });

        // 工具条点击事件
        table.on('tool(maintenanceTableInfo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                showDetailModel(data);
            } else if (obj.event === 'addExecute') {
                //添加认领执行记录
                addExecute(data);
            }
        });

        //监听排序
        table.on('sort(maintenanceTableInfo)', function (obj) {
            table.reload('maintenanceTableInfo', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            data.field.status = data.field.statusSearch;
            data.field.postId = data.field.postIdSearchClaim;
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', data => {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        // 详情弹窗
        function showDetailModel(data) {
            console.log("data", data);
            //deviceFL
            admin.open({
                    type: 1,
                    area: ['1500px', '90%'],
                    offset: '65px',
                    title: '维保任务详情',
                    content: $('#maintenanceDetailForm').html(),
                    success: function () {
                        form.val('maintenanceDetailForm', data);
                        //查询详情并且显示
                        admin.reqSync('enterprise/device/admin/maintenanceClaim/getMaintenanceClaimById', {id: data.id}, function (res) {
                            if (res.code === 200) {
                                let info = res.data;
                                $('#taskTypeNameDetail').val(info.taskTypeName);
                                $('#taskNoDetail').val(info.taskNo);
                                $('#deviceNoDetail').val(info.deviceNo);
                                $('#deviceLXDetail').val(info.deviceTypeName);
                                $('#deviceFLDetail').val(info.categoryName);
                                $('#deviceCXDetail').val(info.workShopName);
                                $('#taskNatureDetail').val(info.taskNatureName);
                                $('#maintenanceTypeDetail').val(info.maintenanceTypeName);
                                $('#deviceLocationDetail').val(info.deviceLocation);
                                $('#departmentIdDetail').val(info.departmentName);
                                $('#postIdDetail').val(info.postName);
                                $('#taskNameDetail').val(info.taskName);
                                //实施前图片
                                if (info.preImg) {
                                    $('#proImage').html('<img class="proPicPath" src="' + data.preImg + '" style="max-width: 183px"/>');
                                    $(".proPicPath").click(function (){
                                        let json = {};
                                        json.attachment = info.preImg;
                                        showViewAttachmentModel(json);
                                    });
                                }

                                if (info.postImg) {
                                    $('#postImage').html('<img class="postPicPath" src="' + data.postImg + '" style="max-width: 183px"/>');
                                    $(".postPicPath").click(function (){
                                        let json = {};
                                        json.attachment = info.postImg;
                                        showViewAttachmentModel(json);
                                    });
                                }
                                $('#totalMoney').val(info.totalMoney + "元");
                                $('#taskRemarkDetail').val(info.taskRemark);
                                $('#createNameDetail').val(info.creatorName);
                                $('#endRemarkDetail').val(info.endRemark);
                                $('#createTimeDetail').val(info.createTime);
                                $('#examineTypeNameDetail').val(info.examineTypeName);
                                $('#examineTimeDetail').val(info.examineTime);
                                $('#claimNoDetail').val(info.claimNo);
                                $('#claimTimeDetail').val(info.claimTime);
                                $('#executeNameDetail').val(info.executeName);
                                $('#executeNoDetail').val(info.executeNo);
                                $('#statusDetail').val(info.statusName);
                                //处置时间
                                $('#executeTimeDetail').val(info.executeTime);

                                //如果物料列表不为空
                                if (Array.isArray(info.maintenanExecuteDetailVos) && info.maintenanExecuteDetailVos.length !== 0) {
                                    table.render({
                                        elem: '#maintenanceExecuteDetailInfo',
                                        data: info.maintenanExecuteDetailVos,
                                        cellMinWidth: 100,
                                        cols: [[
                                            {type: 'numbers', title: '序号', fixed: 'left'}
                                            , {
                                                align: 'center',
                                                field: 'materialNo',
                                                sort: true,
                                                title: '物料编号',
                                                fixed: 'left'
                                            }
                                            , {
                                                align: 'center',
                                                field: 'materialName',
                                                sort: true,
                                                title: '物料名称',
                                                fixed: 'left'
                                            }
                                            , {align: 'center', field: 'materialSpecs', sort: true, title: '物料规格'}
                                            , {align: 'center', field: 'materialCategory', sort: true, title: '物料类别'}
                                            , {align: 'center', field: 'priUnit', sort: true, title: '计价单位'}
                                            , {align: 'center', field: 'onePrice', sort: true, title: '单价'}
                                            , {align: 'center', field: 'consumption', sort: true, title: '用量'}
                                            , {align: 'center', field: 'onePrice', sort: true, title: '用料金额'}
                                            , {align: 'center', field: 'remark', sort: true, title: '备注描述'}
                                        ]]
                                    })
                                }
                            } else {

                            }
                        }, 'get');
                    }
                }
            )
            ;
        }
        function showViewAttachmentModel(data) {
            admin.open({
                type: 1,
                area: ['60%', '80%'],
                offset: '65px',
                title: '查看附件',
                content: $('#viewAttachmentHtml').html(),
                success: function () {
                    if (data.attachment && data.attachment.indexOf(".pdf") !== -1) {
                        PDFObject.embed(data.attachment, "#example1");
                    } else {
                        var attachmentHtml = "";
                        data.attachment.split(",").forEach((attachmentUrl, index) => {
                            attachmentHtml += '<div><div><img src="' + attachmentUrl + '"></div></div>';
                        });
                        $('#example1').html(attachmentHtml);
                    }
                }
            })
        }

        function addExecute(data) {
            console.log("data----", data);
            admin.open({
                type: 1,
                area: ['1400px', '90%'],
                offset: '65px',
                title: '添加认领执行记录',
                content: $('#maintenanceExecuteForm').html(),
                success: function () {


                    let dataDetaillList = [];
                    let erpPurchasePlanInfos = []; //明细数据
                    let usualData = [{}];
                    let codeArr = [];//物料选择集合

                    admin.reqSync('enterprise/device/admin/maintenanceType/getAll', null, function (res) {
                        if (res.code === 200) {
                            loadSelectHtml(res.data, "请选择", "maintenanceType", '[lay-filter="maintenanceExecuteForm"]', 3);
                            if (data != null) {
                                $("#maintenanceType").val(data.maintenanceType);
                                layui.form.render('select');
                            }
                        } else {
                            loadSelectHtml([], "请选择", "maintenanceType", '[lay-filter="maintenanceForm"]', 3);
                        }
                    }, 'get');

                    //初始化设备清单号
                    $('#deviceNo').val(data.deviceId);
                    //初始化维保类型
                    $('#maintenanceType').val(data.maintenanceType);
                    //初始化执行人
                    $('#creatorName').val(config.getUser().nickname);

                    form.val('maintenanceExecuteForm', data);
                    //设置默认值
                    form.render();

                    //时间选择器
                    laydate.render({
                        elem: '#stopTime'
                        , type: 'datetime'
                    });
                    //未添加过执行记录
                    //修改初始化设备清单号
                    admin.reqSync('enterprise/device/admin/device/getDeviceById', {id: data.deviceId}, function (res) {
                        if (res.code === 200) {
                            //类型
                            $('#deviceLX').val(res.data.categoryName);
                            //分类
                            $('#deviceFL').val(res.data.deviceTypeName);
                            //产线
                            $('#deviceCX').val(res.data.workshopName);
                        } else {

                        }
                    }, 'get');

                    //初始化这岗位信息
                    admin.initDataSelect("user/admin/role/getPostData", {roleId: data.departmentId}, "postIdDown", data.postId, "岗位", null, null);

                    //初始化任务名字
                    $('#sbqdbh').text(data.deviceNo);
                    $('#dwh').text("-" + data.deviceLocation);
                    $('#sbmc').text("-" + data.deviceName);
                    taskNature = data.taskNature;
                    if (data.preImg) {
                        $('#ProPic_path').html('<img class="proPicPath" src="' + data.preImg + '" style="max-width: 183px"/>');
                        $(".proPicPath").click(function (){
                            let json = {};
                            json.attachment = data.preImg;
                            showViewAttachmentModel(json);
                        });

                    }
                    if (data.postImg) {
                        $('#PostPic_path').html('<img class="postPicPath" src="' + data.postImg + '" style="max-width: 183px"/>');
                        $(".postPicPath").click(function (){
                            let json = {};
                            json.attachment =  data.postImg;
                            showViewAttachmentModel(json);
                        });
                    }
                    //如果是详情 则要去掉这个上传框
                    //如果是添加
                    $('#ProPicBtn').click(uploadImg('ProPicBtn', 'ProPic_path', 'preImg'));
                    $('#PostPicBtn').click(uploadImg('PostPicBtn', 'PostPic_path', 'postImg'));
                    let myDetail = table.render({
                        elem: '#maintenanExecuteDetailVos',
                        data: [{}],
                        id: 'maintenanExecuteDetailVos',
                        limit: 1,
                        // height: 450,
                        cols: [[
                            {type: 'numbers'},
                            {
                                field: 'materialNo',
                                align: 'center',
                                title: '物料编号',
                                width: '10%',
                                templet: '<div><span class="erpInventoryId" style="display: block;cursor: pointer;" data-add="{{d.materialNo != null ? false : true}}">{{d.materialNo != null ? d.materialNo : "请选择物料"}}</span></div>'
                            },
                            {field: 'materialName', align: 'center', title: '物料名称', width: '10%'},
                            {field: 'materialSpecs', align: 'center', title: '物料规格', width: '10%'},
                            {field: 'materialCategory', align: 'center', title: '物料类别', width: '10%'},
                            {field: 'priUnit', align: 'center', title: '计价单位', width: '10%'},
                            {field: 'onePrice', align: 'center', title: '单价', width: '10%'},
                            {
                                title: "用量<span style='color:red;'>*</span>",
                                align: 'center',
                                field: 'consumption',
                                edit: 'text',
                                width: '10%'
                            },
                            {field: 'oneUserSkuPrice', align: 'center', title: '用料金额', width: '10%'},
                            {field: 'remarkExecute', align: 'center', edit: 'text', title: '备注描述', width: '10%'},
                            {
                                align: 'center',
                                toolbar: '#purchasePlan-edit-table-bar',
                                title: '操作',
                            }
                        ]],
                        done: function () {
                            $(".erpInventoryId").each(function (index) {
                                $(this).click(function () {
                                    var isAdd = $(this).data("add");
                                    //获取物料数据
                                    var erpInventoryList = layer.open({
                                        type: 1,
                                        title: '物料列表',
                                        area: ['1200px', '700px'],
                                        offset: '120px',
                                        content: $('#erpInventoryListEdit').html(),
                                        success: function () {
                                            // 初始化物料分类下拉
                                            admin.initDataSelectTree(true, 'enterprise/product/admin/productType/getTreeData', null, 'selectProductType', null, "物料分类", "addSelfCollectedGoodsProductCategoryId", null);
                                            // 请求物料分类
                                            let arr2tree;
                                            admin.reqSync('enterprise/product/admin/productCategory/getProductCategoryByType', {type: 0}, function (res) {
                                                for (let i = 0; i < res.data.length; i++) {
                                                    res.data[i].children = [];
                                                }
                                                arr2tree = xmSelect.arr2tree(res.data, "parentId", "id", "children", -1);
                                            }, 'get', false);

                                            let smlSelectInstans = xmSelect.render({
                                                el: '#addSelfCollectedGoodsProductCategoryId',
                                                model: {label: {type: 'text'}},
                                                radio: true,
                                                clickClose: true,
                                                filterable: true,
                                                tree: {
                                                    show: true,
                                                    strict: false,
                                                    expandedKeys: [-1],
                                                },
                                                tips: '请选择物料分类',
                                                prop: {
                                                    name: 'name',
                                                    value: 'id',
                                                    children: 'children'
                                                },
                                                data() {
                                                    //填充数据
                                                    return arr2tree;
                                                },
                                                on(data) {
                                                    let parentId = data.arr.length > 0 ? data.change[0].id : "";
                                                    $("input[name='addSelfCollectedGoodsProductCategoryId']").val(parentId);
                                                }
                                            });

                                            form.render("select");

                                            var codes = "";
                                            for (var i = 0; i < codeArr.length; i++) {
                                                if (i == 0) {
                                                    codes = '"' + codeArr[i] + '"';
                                                } else {
                                                    codes += "," + '"' + codeArr[i] + '"';
                                                }
                                            }

                                            // 渲染表格
                                            table.render({
                                                elem: '#erpInventoryListEdit-table',
                                                url: config.base + 'enterprise/product/admin/productDetailWMS/list',
                                                method: 'GET',
                                                where: {
                                                    codes: codes
                                                },
                                                page: true,
                                                cols: [[
                                                    {type: 'checkbox'},
                                                    {field: 'skuCode', align: 'center', title: '物料编号'},
                                                    {field: 'skuName', align: 'center', title: '物料名称'},
                                                    {field: 'costPrice', align: 'center', title: '成本价'},
                                                    {
                                                        field: 'skuSpec',
                                                        align: 'center',
                                                        title: '规格码'
                                                    },
                                                    {
                                                        field: 'pricingMethod',
                                                        align: 'center',
                                                        title: '计价方式',
                                                        templet: function (d) {
                                                            if (d.pricingMethod === "0") {
                                                                return '按件';
                                                            } else if (d.pricingMethod === "1") {
                                                                return '按重量';
                                                            } else {
                                                                return '';
                                                            }
                                                        }
                                                    },
                                                    {
                                                        field: 'productTypeName',
                                                        align: 'center',
                                                        title: '物料分类'
                                                    },
                                                    {field: 'calculateWayName', align: 'center', title: '计量单位'},
                                                    {
                                                        field: 'sellStatus',
                                                        align: 'center',
                                                        title: '是否停用',
                                                        templet: function (d) {
                                                            if (d.sellStatus === "0") {
                                                                return '是';
                                                            } else if (d.sellStatus === "1") {
                                                                return '否';
                                                            } else {
                                                                return '';
                                                            }
                                                        }
                                                    }
                                                ]]
                                            });

                                            // 搜索按钮点击事件
                                            $('#erpInventoryListEdit-btn-search').click(function () {
                                                var name = $('#erpInventoryListEdit-name').val();
                                                var code = $('#erpInventoryListEdit-code').val();
                                                var way = $('#erpInventoryListEdit-way').val();
                                                var categoryId = $('input[name=addSelfCollectedGoodsProductCategoryId]').val();
                                                table.reload('erpInventoryListEdit-table', {
                                                    page: {curr: 1},
                                                    where: {
                                                        skuCode: code,
                                                        skuName: name,
                                                        pricingMethod: way,
                                                        productTypeId: categoryId
                                                    }
                                                });
                                            });

                                            // 确认选择
                                            $('#erpInventoryListEdit-btn-choose').click(function () {
                                                var checkStatus = table.checkStatus('erpInventoryListEdit-table'); //test即为基础参数id对应的值
                                                var dataS = checkStatus.data;
                                                console.log("datas----", dataS);
                                                for (var i = 0; i < dataS.length; i++) {
                                                    //重新组合dataS
                                                    //物料编号
                                                    dataS[i].materialNo = dataS[i].skuCode;
                                                    //物料名称
                                                    dataS[i].materialName = dataS[i].skuName;
                                                    //物料规格
                                                    dataS[i].materialSpecs = dataS[i].skuSpec;
                                                    //物料类别
                                                    dataS[i].materialCategory = dataS[i].productTypeName;
                                                    dataS[i].materialCategoryId = dataS[i].productType;
                                                    //计价单位
                                                    dataS[i].priUnit = dataS[i].calculateWayName;
                                                    //单价
                                                    dataS[i].onePrice = dataS[i].costPrice;
                                                    dataS[i].oneUserSkuPrice = '';
                                                    dataS[i].remarkExecute = '';
                                                }
                                                if (checkStatus.data.length == 0) {
                                                    layer.msg("请选择物料", {icon: 2, time: 1000});
                                                } else {
                                                    layer.close(erpInventoryList);
                                                    if (dataDetaillList.length >= 1) {
                                                        dataDetaillList.splice(dataDetaillList.length - 1, 1);
                                                    }
                                                    if (!isAdd) {
                                                        dataDetaillList.splice(index, 1);
                                                        usualData.splice(index, 1);
                                                        codeArr.splice(index, 1);
                                                        for (var i = 0; i < dataS.length; i++) {
                                                            dataDetaillList.splice(index + i, 0, dataS[i]);
                                                            usualData.splice(index + i, 0, {})
                                                            codeArr.splice(index + i, 0, dataS[i].materialNo);
                                                        }
                                                    } else {
                                                        for (var i = 0; i < dataS.length; i++) {
                                                            dataDetaillList.push(dataS[i]);
                                                            usualData.push({})
                                                            codeArr.push(dataS[i].materialNo);
                                                        }
                                                    }
                                                    //处理数据并存储
                                                    dataDetaillList.push({});
                                                    if (usualData.length - dataDetaillList.length > 0) {
                                                        usualData.splice(dataDetaillList.length + 1, usualData.length - dataDetaillList.length);
                                                    } else {
                                                        var addLength = dataDetaillList.length - usualData.length;
                                                        for (var i = 0; i < addLength; i++) {
                                                            usualData.push({});
                                                        }
                                                    }
                                                    // 获取数据集合并传入请购单中
                                                    table.reload('maintenanExecuteDetailVos', {
                                                        data: dataDetaillList,
                                                        limit: dataDetaillList.length
                                                    });
                                                }
                                            });
                                        }
                                    })
                                })
                            })
                        }
                    });


                    table.on('tool(maintenanExecuteDetailVos)', function (obj) {
                        if (obj.event === 'del') { //删除
                            doDelete(obj);
                        }
                    });

                    //表格修改事件
                    table.on('edit(maintenanExecuteDetailVos)', function (obj) {
                        // 假设我们要根据username字段的变化来更新email字段
                        if (obj.field === 'consumption') {
                            obj.update({
                                oneUserSkuPrice: truncateDecimal(obj.data.consumption * obj.data.costPrice, 2)
                            });
                            //计算金额
                            let data = table.cache['maintenanExecuteDetailVos']
                            let count = 0;
                            $.each(data, function (index, value) {
                                if (value.oneUserSkuPrice != null)
                                    count += value.oneUserSkuPrice;
                            });
                            $('#materialAmount').val(count);
                        }
                    });

                    function truncateDecimal(number, decimalPlaces) {
                        var factor = Math.pow(10, decimalPlaces)
                        return Math.floor(number * factor) / factor
                    }

                    var doDelete = function (obj) {
                        var index = $(obj.tr).data("index");
                        if (!$.isEmptyObject(obj.data)) {
                            layer.confirm('确定要删除吗？', function (i) {
                                layer.close(i);
                                dataDetaillList.splice(index, 1);
                                // erpPurchasePlanInfos.splice(index, 1);
                                usualData.splice(index, 1);
                                if (codeArr.indexOf(obj.data.skuCode) >= 0) {
                                    codeArr.splice(codeArr.indexOf(obj.data.skuCode), 1);
                                }
                                if ($.isEmptyObject(dataDetaillList[0])) {
                                    dataDetaillList = [];
                                    // 获取数据集合并传入请购单中
                                    table.reload('maintenanExecuteDetailVos', {
                                        data: [{}],
                                        limit: 10,
                                    });
                                } else {
                                    // 获取数据集合并传入请购单中
                                    table.reload('maintenanExecuteDetailVos', {
                                        data: dataDetaillList,
                                        limit: dataDetaillList.length
                                    });
                                }
                            });
                        }
                    };

                    //选择框事件
                    form.on('select(deviceNo)', function (data) {
                        //拿到值
                        let deviceId = data.value;
                        admin.reqSync('enterprise/device/admin/device/getDeviceById', {id: deviceId}, function (res) {
                            if (res.code === 200) {
                                console.log("data", res.data);
                                $('#sbqdbh').text(res.data.deviceCode);
                                $('#sbmc').text("-" + res.data.name);
                                //类型
                                $('#deviceLX').val(res.data.categoryName);
                                //分类
                                $('#deviceFL').val(res.data.deviceTypeName);
                                //产线
                                $('#deviceCX').val(res.data.workshopName);
                            } else {

                            }
                        }, 'get');
                    });

                    //点位的改变时间
                    $("#deviceLocation").bind('input propertychange', function () {
                        $('#dwh').text("-" + $("#deviceLocation").val());
                    })


                    //选择框事件
                    // 表单提交事件
                    form.on('submit(maintenanceTypeFormSubmit)', function (d) {
                        layer.load(2);
                        //写死认领任务
                        d.field.taskType = "1";
                        let executeDetail = [];
                        let sbqdbh = $('#sbqdbh').text();
                        let dwh = $('#dwh').text();
                        let sbmc = $('#sbmc').text();
                        let rwlx = $('#rwlx').text();
                        //任务名称
                        d.field.taskName = sbqdbh + dwh + sbmc + rwlx;
                        let detailInfo = table.cache['maintenanExecuteDetailVos'];
                        if (detailInfo.length > 0) {
                            detailInfo.forEach(function (item) {
                                // 假设我们要基于源数组创建全新的对象
                                if (item.id && item) {
                                    let execute = {
                                        materialId: item.id,
                                        dosage: item.consumption,
                                        money: item.oneUserSkuPrice,
                                        remark: item.remarkExecute
                                    }
                                    // 将新对象添加到目标数组中
                                    executeDetail.push(execute);
                                }
                            })
                        }
                        d.field.executeDetail = executeDetail;
                        d.field.taskId = data.taskId;
                        let params = {
                            ...d.field
                        }
                        //新增修改
                        admin.req('enterprise/device/admin/maintenanceExecute/add', JSON.stringify(params), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('maintenanceTableInfo');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST', true, 'application/json; charset=utf-8');
                        console.log("params", params);
                        return false;
                    });

                    //查询设备清单号
                    admin.reqSync('enterprise/device/admin/device/getAll', null, function (res) {
                        if (res.code === 200) {
                            loadSelectHtml(res.data, "请选择", "deviceNo", '[lay-filter="maintenanceExecuteForm"]', 1);
                            if (data) {
                                //修改辅助任务性质
                                $("#deviceNoShowEdit").val(data.deviceId);
                                layui.form.render('select');
                            }
                        } else {
                            loadSelectHtml([], "请选择", "deviceNo", '[lay-filter="maintenanceExecuteForm"]', 1);
                        }
                    }, 'get');

                    admin.reqSync('enterprise/dict/admin/dictLabel/select', {dictType: 'task_nature'}, function (res) {
                        if (res.code === 200) {
                            loadSelectHtml(res.data, "请选择", "taskNature", '[lay-filter="maintenanceExecuteForm"]', 2);
                            if (data != null) {
                                $("#toolDeviceType").val(data.taskNature);
                                layui.form.render('select');
                            }
                        } else {
                            loadSelectHtml([], "请选择", "taskNature", '[lay-filter="maintenanceExecuteForm"]', 2);
                        }
                    }, 'get');

                    //部门列表
                    admin.initDataSelectTree(true, 'user/admin/role/getTreeData', null, 'selectDepartment', data ? data.departmentId : null, "部门", "departmentId", function (data) {
                        // 获取部门ID
                        let departmentId = data.change[0].value;
                        //赋值部门id
                        $('#departmentId').val(data.change[0].value);
                        $('#postIdDown').empty();
                        //部门下的岗位列表
                        admin.initDataSelect("user/admin/role/getPostData", {roleId: departmentId}, "postIdDown", null, "岗位", null, null);
                    });

                    /**
                     * 加载地址HTML
                     * @param data 下拉菜单数据
                     * @param tips select 默认提示
                     * @param htmltarget html要插入的位置
                     * @param name  下拉框需要显示值的属性
                     */
                    function loadSelectHtml(data, tips, htmltarget, formName, type) {
                        let html = ' <option value>' + tips + '</option>';
                        if (!data || data == null) {
                            $("form" + formName + " select[name='" + htmltarget + "']").html(html);
                            form.render('select');
                            return;
                        }
                        for (let i = 0; i < data.length; i++) {
                            if (type == 1) {
                                html += `<option value='${data[i].id}' data='${JSON.stringify(data[i])}'>${data[i].deviceCode}</option>`;
                            } else if (type == 2) {
                                html += `<option value='${data[i].labelValue}' data='${JSON.stringify(data[i])}'>${data[i].labelName}</option>`;
                            } else if (type == 3) {
                                html += `<option value='${data[i].id}' data='${JSON.stringify(data[i])}'>${data[i].name}</option>`;
                            }
                        }
                        $("form" + formName + " select[name='" + htmltarget + "']").html(html);
                        form.render('select');
                    }

                    /**
                     * 统一文件上传
                     * @param _elem
                     * @param pathId
                     * @param inputId
                     */
                    function uploadImg(_elem, pathId, inputId) {
                        upload.render({
                            elem: '#' + _elem
                            , url: config.upload_url + 'uploadFile'
                            , data: {}
                            , accept: 'file'
                            , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx'
                            , headers: {Authorization: 'Bearer ' + config.getToken()}
                            , done: function (res) {
                                if (res.code == 200) {
                                    layer.msg(res.msg || "上传成功", {icon: 1});
                                    let imagUrl = res.data.url;
                                    $('#' + pathId).html('<img class="imageInfo" src="' + imagUrl + '" style="max-width: 183px"/>');
                                    $(".imageInfo").click(function (){
                                        let json = {};
                                        json.attachment = imagUrl;
                                        showViewAttachmentModel(json);
                                    });
                                    $('#' + inputId).val(imagUrl);
                                } else if (res.code == 502) {
                                    return location.replace('admin/login.html');
                                } else {
                                    layer.msg(res.msg || "上传失败", {icon: 2});
                                }
                            }
                        });
                    }
                }
            })
        }

    });
</script>

<!-- 删除操作 -->
<script type="text/html" id="purchasePlan-edit-table-bar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>